package com.jinxin.platform.cdsmsmgr.utils;


import com.alibaba.fastjson.JSONArray;
import com.google.gson.JsonObject;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date:
 * @Author: Lingnan
 **/
public class Test {
    public static void main(String[] args) throws ParseException, UnsupportedEncodingException {
        final Base64.Decoder decoder = Base64.getDecoder();
        final Base64.Encoder encoder = Base64.getEncoder();
        final String text = "字串文郭德纲豪华型和好附件复活甲回复江湖救急地方唧唧复唧唧字";
        final byte[] textByte = text.getBytes("UTF-8");
//编码
        final String encodedText = encoder.encodeToString(textByte);
//        System.out.println(encodedText);
////解码
//        System.out.println(new String(decoder.decode("R0lGODlhHAAmAKIHAKqqqsvLy0hISObm5vf394uLiwAA"), "UTF-8"));
//        System.out.println(new Date());
//        System.out.println(DateUtil.parseStr(DateUtil.df.format(new Date()),"yyyy-MM-dd HH:mm:ss"));



        // 待处理字符串
        String wpp = "您的验证码：${code}，您正进行身份验证${name}，打死不告诉别人！";
        //\u0024\u007B\u0028\u002E\u002A\u003F\u0029}
        // 匹配方式
        Pattern p = Pattern.compile("\\$\\{(.*?)}");
        // 匹配】


        // 处理匹配到的值
//        int count=0;
//        int index =0;
//        List<String> paramList = new ArrayList<>();
//        paramList.add("123456");
//        paramList.add("李四");
//        paramList.add("gjdgjdgkls");

//        String[] valueArr = new String[]{"123","李四","gjdgjdgkls"};
//        while (matcher.find()) {
//            count++;
//        }
//        if(count == valueArr.length){
//            System.out.println("11111111111");
//        }
//        JsonObject jsonO=new JsonObject();
//        while (matcher.find()) {
//            count++;
//            if(count > paramList.size()){ //2  3
//                System.out.println("error");
//                return;
//            }
//            String group = matcher.group();
//            System.out.println("woo: " + group.substring(2,group.length()-1));
//            jsonO.addProperty(group.substring(2,group.length()-1),paramList.get(index));
//            jsonArry[index] = jsonO;
//            index++;

//        }
//        if(count < paramList.size()){
//            System.out.println("err2");
//        }
//        System.out.println(jsonO.toString());

        String steter = "aaaa,123";
        String[] strings = steter.split(";");
        JsonObject[] jsonArry=new JsonObject[strings.length];
        for (int i = 0; i < strings.length; i++) {
            String[] split = strings[i].split(",");
            int count=0;   //匹配的数量
            int index =0;
            JsonObject jsonObject = new JsonObject();
            Matcher matcher = p.matcher(wpp);
            while (matcher.find()){
                count++;
                if(count > split.length){
                    System.out.println("error1");
                    return;
                }
                String group = matcher.group();
                jsonObject.addProperty(group.substring(2,group.length()-1),split[index]);
                jsonArry[index] = jsonObject;
                index++;
            }
            if(count < split.length){
                System.out.println("error2");
                return;
            }
        }
        List<String> phoneList = Arrays.asList("123,456".split(","));
        JSONArray jsonArray = new JSONArray();
        jsonArray.addAll(phoneList);
        System.out.println(jsonArray.toString());
        System.out.println(Arrays.asList("".split(";")));

    }
}
